import vue from '@vitejs/plugin-vue'
import { viteAutoImport } from './viteAutoImport'
import { viteComponents } from './viteComponents'
import { viteSetupExtend } from './viteSetupExtend'
import { viteCompression } from './viteCompression'
import { viteMock } from './viteMock'

/**
 * 生成 vite 插件
 * @param {env} viteEnv 环境变量
 * @param {String} viteCommand 指令 serve | build
 * @returns vite 插件数组
 */
export default function createVitePlugins(viteEnv, viteCommand) {
  const vitePlugins = [vue()]

  vitePlugins.push(viteAutoImport())
  vitePlugins.push(viteComponents())
  vitePlugins.push(viteSetupExtend())

  if (viteCommand === 'build') {
    vitePlugins.push(viteCompression(viteEnv))
  }

  if (viteCommand === 'serve') {
    vitePlugins.push(viteMock(viteEnv))
  }

  return vitePlugins
}
